/*
 * File: binsearch_u32u16.c
 *
 * Code generated for Simulink model 'SOCE'.
 *
 * Model version                  : 3.270
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Mon Apr  3 13:38:00 2023
 */

#include "rtwtypes.h"
#include "binsearch_u32u16.h"

uint32_T binsearch_u32u16(uint16_T u, const uint16_T bp[], uint32_T startIndex,
    uint32_T maxIndex)
{
    uint32_T bpIdx;
    uint32_T bpIndex;
    uint32_T iRght;

    /* Binary Search */
    bpIdx = startIndex;
    bpIndex = 0U;
    iRght = maxIndex;
    while (iRght - bpIndex > 1U)
    {
        if (u < bp[bpIdx])
        {
            iRght = bpIdx;
        }
        else
        {
            bpIndex = bpIdx;
        }

        bpIdx = (iRght + bpIndex) >> 1U;
    }

    return bpIndex;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */